import axios from 'axios'
import log from "./log"

const require = axios.create({
  timeout: 10000,
  withCredentials: true,
})

require.interceptors.request.use(config => {
  // console.log("request config ==> ", config);
  return config
})

require.interceptors.response.use(config => {
  // console.log("response config ==> ", config);
  log(config)
  let {status} = config
  let {url, method} = config.config
  // console.log(config.config.url);
  // console.log(config.config.method);
  // return config.data
  return config
},
error => {
  // console.log("error ==> ", error);
  let { message, response } = error
  // console.log("message ==> ", message);
  // console.log("response ==> ", response);
  const { status } = response
  const { msg, result } = response.data

  switch(status){
    case 401:
      console.log("401=======================");
      
      return location.replace(`${result}/#/admin/login?goto=${encodeURIComponent(window.location.href)}`)
    default: 

  }

  
})

export default require



